package com.zhsq.zlc.service.user;

import com.zhsq.zlc.entity.UserEntity;
import com.zhsq.zlc.dao.user.UserMapper;
import com.zhsq.zlc.util.MD5Util;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public UserEntity findByNameAndPassword(UserEntity entity) {
        entity.setPassword(MD5Util.getMD5Str(entity.getPassword()));
        return userMapper.findByLoginNameAndPassword(entity);
    }

    @Override
    public List<UserEntity> list(UserEntity entity) throws Exception {
        return userMapper.list(entity);
    }

    @Override
    public UserEntity getUserById(UserEntity entity) throws Exception {
        return userMapper.getUserById(entity).get(0);
    }

    @Override
    public int count(UserEntity entity) throws Exception {
        return userMapper.count(entity);
    }

    @Override
    public void add(UserEntity entity) throws Exception {
        userMapper.add(entity);
    }

    @Override
    public void edit(UserEntity entity) throws Exception {
        userMapper.edit(entity);
    }

    @Override
    public void delete(int id) throws Exception {
        userMapper.delete(id);
    }


}
